package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 会员层级关系来源枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2020-08-18
 */
public enum MemberRelationSourceEnum {

    /**
     * 通过Web注册成为下级会员 - 0
     */
    WEB_REGISTER(0, "通过Web注册成为下级会员"),

    /**
     * 通过移动端注册成为下级会员 - 1
     */
    MOBILE_REGISTER(1, "通过移动端注册成为下级会员"),

    /**
     * 通过新增角色成为下级会员 - 2
     */
    ADD_ROLE(2, "通过新增角色成为下级会员"),

    /**
     * 通过平台后台创建 - 3
     */
    PLATFORM_CREATE(3, "通过平台后台创建"),

    /**
     * 通过会员能力创建 - 4
     */
    MEMBER_CREATE(4, "通过会员能力创建"),

    /**
     * 在“店铺”中主动申请成为下级会员 - 5
     */
    APPLY_TO_BE(5, "主动申请成为下级会员"),

    /**
     * 未知 - 99
     */
    UNKNOWN(99, "未知");

    private final Integer code;

    MemberRelationSourceEnum(Integer code, String message) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static MemberRelationSourceEnum parse(Integer code) {
        return Arrays.stream(MemberRelationSourceEnum.values()).filter(t -> t.getCode().equals(code)).findFirst().orElse(MemberRelationSourceEnum.UNKNOWN);
    }

    public static MemberRelationSourceEnum parseFromRegisterSource(MemberRegisterSourceEnum registerSourceEnum) {
        MemberRelationSourceEnum relationSourceEnum;
        switch (registerSourceEnum) {
            case FROM_ENTERPRISE_WEB_SHOP:
            case FROM_CHANNEL_WEB_SHOP:
                relationSourceEnum = WEB_REGISTER;
                break;
            case FROM_ENTERPRISE_H5_WEB_SHOP:
            case FROM_CHANNEL_H5_WEB_SHOP:
            case FROM_ENTERPRISE_APP_SHOP:
            case FROM_CHANNEL_APP_SHOP:
            case FROM_CHANNEL_APP_PROPERTY_SHOP:
            case FROM_ENTERPRISE_APP_SCORE_SHOP:
            case FROM_CHANNEL_APP_SCORE_SHOP:
                relationSourceEnum = MOBILE_REGISTER;
                break;
            case FROM_PLATFORM_IMPORT:
            case FROM_MANAGE_PLATFORM:
                relationSourceEnum = PLATFORM_CREATE;
                break;
            case FROM_MERCHANT_IMPORT:
            case FROM_CHANNEL_IMPORT:
                relationSourceEnum = MEMBER_CREATE;
                break;
            default:
                relationSourceEnum = UNKNOWN;
                break;
        }

        return relationSourceEnum;
    }
}
